import './add.less';
import Panel from "./../../elements/Panel";
import Header from "./../../components/Header";
import Modal from "./../../components/Modal/";
import {connect} from "react-redux";
import CONFIG from "./../../libs/config";
import {Lang, Fetch, Fetch_} from "./../../libs/";
import {URL, md5Url} from "./../../libs/Url";
import Label from "./../../components/FormLabel";
import FormGroup from "./../../components/FormGroup";
import FormItem from "./../../components/FormItem";
import FormItemRef from "./../../components/FormItemRef";
import Lesson from "./../../components/form/lesson";
import FormItemType from "./../../components/FormItemType";
import InputGroup from "./../../components/InputGroup";
import Selected from "./../../components/SelectItem";
import {Warn} from "./../../components/alert/";
import BreadcrumbNavigation from "./../../components/BreadcrumbNavigation";
import SingleSelectClass from "./../../components/form/single_select_class";
import {fetch, fetchUser} from "../../actions";
import {SUBJECT, PAGE_SUBJECT} from "./../../actions/subject";


const AddTeachSchedule = React.createClass({
    getInitialState(){
        const self = this;
        this.isUpdate = this.props.router.params.id;

        return {}
    },

    componentDidMount() {
        const {dispatch, user} = this.props, self = this;
        if (this.isUpdate) {
            Promise.all([
                Fetch(URL.TEACH_SCHEDULE_GET,
                    {
                        body: {teachingid: this.isUpdate}
                    }),
                Fetch(URL.TEACH_SCHEDULE_FIND_ITEM,
                    {
                        body: {teachingid: this.isUpdate}
                    })
            ])
                .then(res=> {
                    var course = (res[1].coureses);
                    var tp = res[0].teachingplan;
                    tp.tuisong = res[0]['class'];
                    var schedule_lesson = Object.keys(course).map((item, index)=> {
                        item = course[item];
                        return {
                            name: item.courseInfo.name,
                            comment: item.courseInfo.comment,
                            fileids: item.courseInfo.fileids,
                            courseid: item.courseInfo.id,
                            courseList: item.classInfo.map((item_, index)=> {
                                return {
                                    class_: {
                                        'class': item_
                                    },
                                    teachid: self.isUpdate,
                                    time: item_.time
                                }
                            })
                        };
                    });
                    self.setState({
                        schedule: tp,
                        schedule_lesson: schedule_lesson
                    })
                })
                .catch(e=> {
                    console.log(e)
                })
        }
    },


    render(){
        const self = this;
        const {user, dispatch}  = this.props;
        const form = this.props[PAGE_SUBJECT.NEWS_ADD].form;
        const data_category = self.props[md5Url.CATEGORY_FIND] || {};
        (!data_category.list && (data_category.list = []));
        var data = this.state.schedule || {tuisong: []};
        var schedule_lesson = this.state.schedule_lesson || [];
        return (
            <div>
                <BreadcrumbNavigation navs={[
                    {url: CONFIG.MENUS_ABSOLUTE.HOME, label: Lang.menus.HOME},
                    {url: CONFIG.MENUS_ABSOLUTE.TEACH_SCHEDULE, label: Lang.menus.TEACH_SCHEDULE},
                    {label: Lang.menus.TEACH_SCHEDULE_DETAIL},
                ]}>
                </BreadcrumbNavigation>
                <Panel>
                    <Header>{this.isUpdate ? Lang.menus.TEACH_SCHEDULE_DETAIL : Lang.menus.TEACH_SCHEDULE_ADD}</Header>
                    <Warn>
                        <strong>说明：</strong>1、添加本学期的教学计划总纲； 2.保存成功后，可进行课时安排的添加；
                    </Warn>
                    <h5 className="add-h5">教学计划总纲</h5>
                    <div className="teachPlan">
                        <div className="title"><b>{data.name}</b> <span className="pull-right">
                            <i className="fa fa-angle-double-down"></i></span></div>
                        <form className="form-horizontal text">
                            <div className="form-group">
                                <label className="col-sm-2 control-label">科目：</label>
                                <div className="col-sm-10">
                                    <div style={{paddingTop: '7px'}}>{data.name}</div>
                                </div>
                            </div>
                            <div className="form-group">
                                <label className="col-sm-2 control-label">教师：</label>
                                <div className="col-sm-10">
                                    <div style={{paddingTop: '7px'}}>{data.name}</div>
                                </div>
                            </div>
                            <div className="form-group">
                                <label className="col-sm-2 control-label">推送班级：</label>
                                <div className="col-sm-10">
                                    <div style={{paddingTop: '7px'}}>{data.tuisong.map((item)=> {
                                        return item.name
                                    }).toString()}</div>
                                </div>
                            </div>
                            <div className="form-group">
                                <label className="col-sm-2 control-label">学情分析：</label>
                                <div className="col-sm-10">
                                    <div style={{paddingTop: '7px'}}> {data.analysis}
                                    </div>
                                </div>
                            </div>
                            <div className="form-group">
                                <label className="col-sm-2 control-label">教学目标：</label>
                                <div className="col-sm-10"> {data.target}
                                </div>
                            </div>
                            <div className="form-group">
                                <label className="col-sm-2 control-label">重点/难点：</label>
                                <div className="col-sm-10"> {data.keypoint}
                                </div>
                            </div>

                        </form>
                    </div>
                    <div>
                        <h5 className="add-h5">课时安排</h5>
                        <div className="lessonPlan">
                            {
                                schedule_lesson.map((item, index_)=> {
                                    return <dl key={index_}>
                                        <dt>{index_ + 1}、{item.name}
                                            <span>

                                                </span>
                                            <i className="open fa fa-angle-down"></i>
                                        </dt>
                                        {item.courseList.map((itemc, indexc)=> {
                                            return <dd key={indexc}>
                                                <b>{itemc.class_['class'].name}</b>
                                                <span>
                                                    <i>推送时间：</i>
                                                    {itemc.time || '未设置推送时间'}
                                                </span>
                                            </dd>
                                        })}

                                    </dl>
                                })
                            }

                        </div>

                    </div>

                </Panel>
            </div>
        )
    }
});
function select(state) {
    return {
        user: state.user.user,
        [md5Url.CATEGORY_FIND]: state.fetchBySubject[md5Url.CATEGORY_FIND],
        [md5Url.NEWS_ADD]: state.fetchBySubject[md5Url.NEWS_ADD],
        [PAGE_SUBJECT.NEWS_ADD]: state.pageBySubject[PAGE_SUBJECT.NEWS_ADD]
    }
}
export default connect(select)(AddTeachSchedule)